package com.xsm.adapter;

import com.xsm.activitygroup.R;

import android.R.integer;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TabAdapter extends BaseAdapter{
	String texts[];
	int icons[];
	int selecticons[];
	Context context;
	LayoutInflater inflater;
	ViewHolder holder;
	boolean[] isSelected;
	public TabAdapter(Context context,String texts[],int icons[],int[] selecticons){
		this.texts=texts;
		this.icons=icons;
		this.selecticons=selecticons;
		this.context=context;
		inflater=LayoutInflater.from(context);
		isSelected=new boolean[texts.length];
		for(int i=0;i<texts.length;i++){
			isSelected[i]=false;
		}
	}
	public int getCount() {
		return 	texts.length;
	}

	public Object getItem(int arg0) {
		return texts[arg0];
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@SuppressLint("ResourceAsColor")
	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		holder=new ViewHolder();
		if(arg1==null){
			arg1=inflater.inflate(R.layout.tabitem, null);
			holder.tabLayout=(LinearLayout)arg1.findViewById(R.id.tablayout);
			holder.icon=(ImageView)arg1.findViewById(R.id.tabicon);
			holder.text=(TextView) arg1.findViewById(R.id.tabtext);
			arg1.setTag(holder);
		}else {
	    holder=(ViewHolder)arg1.getTag();
		}
		
		if(isSelected[arg0])
		{holder.icon.setBackgroundResource(selecticons[arg0]);
		holder.tabLayout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.tab_bg));
		holder.text.setTextColor(R.color.green);
		}else
		{
			holder.icon.setBackgroundResource(icons[arg0]);
			holder.tabLayout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.tab_bg));
			holder.text.setTextColor(R.color.textcolor);
		}
		
		holder.text.setText(texts[arg0]);
		return arg1;
	}

	 public void setSelected(int i,boolean s){
		 isSelected[i]=s;
	 }
	 public boolean[] getSelected(){
		 return isSelected;
	 }
}
class ViewHolder{
	LinearLayout tabLayout;
	ImageView icon;
	TextView text;
}
